package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.StoredCard;
import com.red.star.wechat.data.entity.SuperPojo;
import com.red.star.wechat.data.entity.vo.CardPayInfo;
import com.red.star.wechat.data.entity.vo.CardReadInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author
 * @Description:蓄客卡Mapper
 * @create 2018-02-27 19:31
 **/
public interface StoredCardMapper extends MyMapper<StoredCard> {

    public void addCardAndgroup(@Param("id") Integer id, @Param("groupId") Integer groupId);

    public void updateCardAndgroup(@Param("id") Integer id, @Param("cId") Integer cId, @Param("groupId") Integer groupId);

    public void doUpdate(StoredCard storedCard);

    public List<StoredCard> queryByStoredCards(StoredCard storedCard);

    public List<StoredCard> getAllStoredCard(@Param("mallCode") String mallCode);

    public void updateDeleteGroupById(@Param("id") Integer id);

    public void changeStatusById(@Param("id") Integer id);

    public StoredCard findOne(@Param("id") Integer id);

    public void changeStatusById(@Param("id") Integer id, @Param("status") Integer status);

    public List<SuperPojo> queryStoredAndMallAndEmployAndMerchant(SuperPojo superPojo);

    public List<SuperPojo> queryStoredAndVipAndFansCardAndMallAndMerchant(SuperPojo superPojo);

    public List<SuperPojo> queryMallAndEmployAndMerchantAndFans(SuperPojo superPojo);

    @Select(value = "select * from t_stored_card where name =#{name} and mall_code = #{mallCode}")
    public StoredCard getStoredCardByNameAndMallCode(@Param("name") String name, @Param("mallCode") String mallCode);

    public List<String> findNameList(@Param("cardName") String cardName);

    @Select(value = "select DISTINCT t.coupons_package_id from t_stored_card t where (NOW() BETWEEN t.start_time and t.end_time) and t.status = 1")
    public List<Integer> findOnlyEffectiveMallCode();

    StoredCard findLastByFansAndGroup(@Param("cFansId") Integer cFansId, @Param("groupId") Integer groupId);

    StoredCard findTimeAndMallAndGroup(@Param("mallCode") String mallCode, @Param("startTime") Date startTime, @Param("groupId") Integer groupId, @Param("storedCardId") Integer storedCardId);

    List<StoredCard> listStoredCardByEmployee(@Param("employeeId") Integer employeeId);

    @Select(value = "SELECT count(t.id) FROM t_stored_card t WHERE t.end_time > now() and t.STATUS = 1 AND t.activity_id = #{activityId}")
    Integer countByActivityId(@Param("activityId") Integer activityId);

    Integer countByIdAIncome(@Param("cardId") Integer cardId);

    @Select("select * from t_stored_card t where t.mall_code = #{mallCode} order by t.create_time desc ")
    List<StoredCard> findByMallCode(@Param("mallCode") String mallCode);

    List<CardReadInfo> listCardReadInfoYesterday();

    List<CardPayInfo> listCardPayInfoYesterday();

    List<CardReadInfo> listAllCardReadInfo();

    List<CardPayInfo> listAllCardPayInfo();

    List<CardPayInfo> listCardLeaveInfo();

    List<CardPayInfo> listAllCardLeaveInfo();

    void updateDeleteActivity(@Param("id") Integer id);

    @Select("select count(t.id) from t_stored_card t where t.`status` = 1 and t.id = #{cardId}")
    Integer countEffectiveByCardId(@Param("cardId") Integer cardId);

    List<StoredCard> findStoredCardByIds(@Param("list")List<Integer> list);

    /**
     * 根据id查询激励条件
     * @param cardId
     * @return
     */
    @Select("select t.excitation_type from t_stored_card t where t.id = #{cardId}")
    int findExcitationTypeById(@Param("cardId") Integer cardId);
}
